//
//  SendFactoryViewController.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/7/13.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "SendFactoryViewController.h"
#import "BGTextView.h"

@interface SendFactoryViewController ()<UITextViewDelegate>
{
    
}

@property (nonatomic,strong) BGTextView *textView;
@end

@implementation SendFactoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self UISetting];
}


- (void)UISetting{
    _layoutWidth.constant = kScreenSize.width;
    _layoutHeight.constant = 470;
    
    _buttonSure.layer.masksToBounds = YES;
    _buttonSure.layer.cornerRadius = 5;
    
    [self creatTextView];
    _model.user = [[UserModel alloc] init];
    [_model.user setValuesForKeysWithDictionary:_model.employee];
    
    _labelNumber.text = [NSString stringWithFormat:@"充电宝设备编号：%@",_powerId];
    
    _labelMer.text = _model.user.name;
    
    _labelMerTel.text = _model.user.mobile;
    
    _labelDate.text = _model.created;
    
    _textView.text = _model.content;
    
    UITapGestureRecognizer *tapRecognizerTel=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callFun)];
    
    _labelMerTel.userInteractionEnabled=YES;
    [_labelMerTel addGestureRecognizer:tapRecognizerTel];
}

- (void)callFun{
    
    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_labelMerTel.text];
    UIWebView *callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

#pragma mark - 点击事件

- (IBAction)backButtonClick:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

//点击确认
- (IBAction)sureButtonClick:(UIButton *)sender {

    [self.hub hideAnimated:YES];
    
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // Set the label text.
    self.hub.label.text = NSLocalizedString(@"加载中...", @"HUD loading title");
    
    [[AFClient shareInstance] sendFactoryByEid:kUserId alias:_powerId progressBlock:nil success:^(id responseBody) {
        [self.hub hideAnimated:YES];
        if ([responseBody[@"code"] integerValue] == 200) {
            [self alertVCByTitle:@"操作成功"];
        }else{
            [self alertVCByTitle:responseBody[@"message"]];
            
        }
    } failure:^(NSError *error) {
        [self.hub hideAnimated:YES];
    }];
}


#pragma mark - 创建textView

- (void )creatTextView{
    
    _textView = [[BGTextView alloc] initWithFrame:CGRectMake(10, 10, kScreenSize.width - 20, _viewTextView.sizeHeight - 20)];
    _textView.textFont = [UIFont systemFontOfSize:15];
    if ([BGFunctionHelper isNULLOfString:_model.content]) {
        _textView.placeholderStr = @"备注可留空";
    }else{
        _textView.placeholderStr = @"";
    }
    _textView.placeholderColor = kColorFrom0x(0xbebebe);
    _textView.textViewTextColor = [UIColor blackColor];
    _textView.backgroundColor = kColorFrom0x(0xf4f4f4);
    
    _textView.tintColor = [UIColor blackColor];
    //    _textView.keyboardType = UIKeyboardTypeNumberPad;
    [_textView updateInfo];
    _textView.delegate = self;
    [_viewTextView addSubview:_textView];
}


- (void)textViewDidChange:(UITextView *)textView{
    [_textView textViewDidChange:textView];
}

- (void)alertVCByTitle:(NSString *)title{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }];
    
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
